/**
 *
 * @author Osvaldo Rosado
 */

import java.io.File;

public class Delete {
  public static void Delete(String filename) {
    File file = new File(filename);
    if (!file.exists()){
      throw new IllegalArgumentException("Could not find " + filename + " for deletion.");
    }

    if (!file.canWrite()){
      throw new IllegalArgumentException("Could not delete "
          + filename);
    }

    if (file.isDirectory()) {
      String[] files = file.list();
      if (files.length > 0)
        throw new IllegalArgumentException(
            "Could not delete non-empty directory " + filename);
    }

    boolean success = file.delete();

    if (!success)
      throw new IllegalArgumentException("Could not delete " + filename);
  }

}
